home *** CD-ROM | disk | FTP | other *** search
/ Power CD / Power CD ATARI-Rechner Lieben.iso / ALLERLEI / GOBJ_112 / SOURCE / ZEIT / ZEIT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-04-14  |  6.0 KB  |  223 lines

  1. {$IFDEF DEBUG}
  2.     {$B+,D+,G-,I-,L+,N-,P-,Q+,R+,S+,T-,V-,X+,Z+}
  3. {$ELSE}
  4.     {$B+,D-,G-,I-,L-,N-,P-,Q-,R-,S-,T-,V-,X+,Z+}
  5. {$ENDIF}
  6.  
  7. program Zeit;
  8.  
  9. uses
  10.  
  11.     Tos,Gem,OTypes,OProcs,OWindows;
  12.  
  13. const
  14.  
  15.     {$I zeit.i}
  16.  
  17. type
  18.  
  19.     PZeitApplication = ^TZeitApplication;
  20.     TZeitApplication = object(TApplication)
  21.         icn1,icn2: PControl;
  22.         edt      : PEdit;
  23.         oldtime  : string;
  24.         procedure InitInstance; virtual;
  25.         procedure InitMainWindow; virtual;
  26.         procedure HandleTimer; virtual;
  27.     end;
  28.  
  29.     PZeitDialog = ^TZeitDialog;
  30.     TZeitDialog = object(TDialog)
  31.         edz,edd: PEdit;
  32.         procedure GetWindowClass(var AWndClass: TWndClass); virtual;
  33.         function GetStyle: integer; virtual;
  34.         function OK: boolean; virtual;
  35.         function Cancel: boolean; virtual;
  36.         function Help: boolean; virtual;
  37.     end;
  38.  
  39. var
  40.  
  41.     ZeitApplication: TZeitApplication;
  42.  
  43.  
  44. procedure ZeitResource; external; {$L zeit.o}
  45.  
  46.  
  47. procedure TZeitApplication.InitInstance;
  48.  
  49.     begin
  50.         InitResource(@ZeitResource,nil);
  51.         Attr.EventMask:=Attr.EventMask or MU_TIMER;
  52.         inherited InitInstance
  53.     end;
  54.  
  55.  
  56. procedure TZeitApplication.InitMainWindow;
  57.     var p   : PZeitDialog;
  58.         wert: word;
  59.  
  60.     begin
  61.         new(p,Init(nil,'Zeit+Datum',DIALOG));
  62.         if (MainWindow=nil) or (ChkError<em_OK) then Status:=em_InvalidMainWindow
  63.         else
  64.             begin
  65.                 new(PButton,Init(p,OK,id_OK,true,'Setzt die neue Zeit und das Datum'));
  66.                 new(PButton,Init(p,ABBRUCH,id_Cancel,true,'Bricht den Dialog ab, ohne die neuen Werte zu setzen'));
  67.                 new(PButton,Init(p,HILFE,id_Help,true,'Zeigt einen Hilfstext an'));
  68.                 new(p^.edz,Init(p,EDZEIT,7,'In diesem Feld wird die Zeit im Format mm:hh:ss angegeben. Die Sekunden brauchen nicht angegeben zu werden, es wird'
  69.                                             +' dann 00 verwendet. Die Zeit wird so lange automatisch aktualisiert, bis der Text vom Benutzer verändert wird.'));
  70.                 new(p^.edd,Init(p,EDDATUM,9,'In diesem Feld wird das Datum im Format tt:mm:jj bzw. tt:mm:jjjj eingegeben'));
  71.                 edt:=p^.edz;
  72.                 new(icn1,Init(p,ICON1,'ObjectGEM "Zeit+Datum"|geschrieben von Thomas Much|Version 09.04.1994'));
  73.                 new(icn2,Init(p,ICON2,'ObjectGEM "Zeit+Datum"|geschrieben von Thomas Much|Version 09.04.1994'));
  74.                 wert:=tgetdate and $001f;
  75.                 if wert<10 then oldtime:='0' else oldtime:='';
  76.                 oldtime:=oldtime+ltoa(wert);
  77.                 wert:=(tgetdate and $01e0) shr 5;
  78.                 if wert<10 then oldtime:=oldtime+'0';
  79.                 p^.edd^.SetText(oldtime+ltoa(wert)+ltoa((tgetdate shr 9)+1980));
  80.                 wert:=tgettime shr 11;
  81.                 if wert<10 then oldtime:='0' else oldtime:='';
  82.                 oldtime:=oldtime+ltoa(wert);
  83.                 wert:=(tgettime and $07e0) shr 5;
  84.                 if wert<10 then oldtime:=oldtime+'0';
  85.                 oldtime:=oldtime+ltoa(wert);
  86.                 wert:=(tgettime and $001f) shl 1;
  87.                 if wert<10 then oldtime:=oldtime+'0';
  88.                 oldtime:=oldtime+ltoa(wert);
  89.                 edt^.SetText(oldtime);
  90.                 icn2^.Hide(true);
  91.                 icn1^.Unhide;
  92.                 if AppFlag then p^.MakeWindow
  93.             end
  94.     end;
  95.  
  96.  
  97. procedure TZeitApplication.HandleTimer;
  98.     var wert   : word;
  99.         newtime: string;
  100.  
  101.     begin
  102.         if edt^.GetText=oldtime then
  103.             begin
  104.                 wert:=tgettime shr 11;
  105.                 if wert<10 then newtime:='0' else newtime:='';
  106.                 newtime:=newtime+ltoa(wert);
  107.                 wert:=(tgettime and $07e0) shr 5;
  108.                 if wert<10 then newtime:=newtime+'0';
  109.                 newtime:=newtime+ltoa(wert);
  110.                 wert:=(tgettime and $001f) shl 1;
  111.                 if wert<10 then newtime:=newtime+'0';
  112.                 newtime:=newtime+ltoa(wert);
  113.                 if oldtime<>newtime then edt^.SetText(newtime);
  114.                 oldtime:=newtime
  115.             end;
  116.         if icn1^.IsHidden then
  117.             begin
  118.                 if Attr.Colors>2 then
  119.                     icn1^.SetColor((icn2^.GetColor+1) mod Min(16,Attr.Colors));
  120.                 icn2^.Hide(true);
  121.                 icn1^.Unhide
  122.             end
  123.         else
  124.             begin
  125.                 if Attr.Colors>2 then
  126.                     icn2^.SetColor((icn1^.GetColor+1) mod Min(16,Attr.Colors));
  127.                 icn1^.Hide(true);
  128.                 icn2^.Unhide
  129.             end
  130.     end;
  131.  
  132.  
  133. procedure TZeitDialog.GetWindowClass(var AWndClass: TWndClass);
  134.  
  135.     begin
  136.         inherited GetWindowClass(AWndClass);
  137.         with AWndClass do Style:=Style or cs_CreateOnAccOpen
  138.     end;
  139.  
  140.  
  141. function TZeitDialog.GetStyle: integer;
  142.  
  143.     begin
  144.         GetStyle:=inherited GetStyle or SIZER or FULLER
  145.     end;
  146.  
  147.  
  148. function TZeitDialog.OK: boolean;
  149.     var valid   : boolean;
  150.         td      : string;
  151.         hr,mn,sk,
  152.         tg,mo,jr: word;
  153.  
  154.     begin
  155.         valid:=inherited OK;
  156.         hr:=0; { damit der Compiler nicht meckert... }
  157.         mn:=0;
  158.         sk:=0;
  159.         tg:=0;
  160.         mo:=0;
  161.         jr:=0;
  162.         if valid then
  163.             begin
  164.                 td:=edz^.GetText;
  165.                 if (length(td)<>4) and (length(td)<>6) then valid:=false
  166.                 else
  167.                     begin
  168.                         if length(td)=4 then td:=td+'00';
  169.                         hr:=atol(StrPLeft(td,2));
  170.                         mn:=atol(copy(td,3,2));
  171.                         sk:=atol(StrPRight(td,2));
  172.                         valid:=Between(hr,0,23) and Between(mn,0,59) and Between(sk,0,59)
  173.                     end;
  174.                 if not(valid) then Application^.Alert(@self,1,STOP,'Bitte geben Sie eine korrekte Zeit ein!','  &OK  ')
  175.             end;
  176.         if valid then
  177.             begin
  178.                 td:=edd^.GetText;
  179.                 if (length(td)<>6) and (length(td)<>8) then valid:=false
  180.                 else
  181.                     begin
  182.                         if length(td)=6 then td:=StrPLeft(td,4)+'19'+StrPRight(td,2);
  183.                         jr:=atol(StrPRight(td,4));
  184.                         mo:=atol(copy(td,3,2));
  185.                         tg:=atol(StrPLeft(td,2));
  186.                         valid:=Between(jr,1980,2099) and Between(mo,1,12) and Between(tg,1,31)
  187.                     end;
  188.                 if not(valid) then Application^.Alert(@self,1,STOP,'Bitte geben Sie ein korrektes Datum ein!','  &OK  ')
  189.             end;
  190.         if valid then
  191.             begin
  192.                 tsettime((hr shl 11) or (mn shl 5) or (sk shr 1));
  193.                 tsetdate(((jr-1980) shl 9) or (mo shl 5) or tg);
  194.                 Application^.Quit
  195.             end;
  196.         OK:=valid
  197.     end;
  198.  
  199.  
  200. function TZeitDialog.Cancel: boolean;
  201.     var valid: boolean;
  202.  
  203.     begin
  204.         valid:=inherited Cancel;
  205.         if valid then Application^.Quit;
  206.         Cancel:=valid
  207.     end;
  208.  
  209.  
  210. function TZeitDialog.Help: boolean;
  211.  
  212.     begin
  213.         Application^.Alert(@self,1,NOTE,'Bringen Sie den Mauscursor auf das Dialogelement, für das Sie Hilfe benötigen. Drücken Sie dann die <Help>- oder die rechte Maus-Taste.','  &OK  ');
  214.         Help:=false
  215.     end;
  216.  
  217.  
  218. begin
  219.   { if ((tgetdate shr 9)>=14) and AppFlag then halt; ... }
  220.   ZeitApplication.Init('ZEIT','Zeit+Datum');
  221.   ZeitApplication.Run;
  222.   ZeitApplication.Done
  223. end.